home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fritz: All Fritz
/
All Fritz.zip
/
All Fritz
/
FILES
/
PROGASIC
/
BASFILES.LZH
/
NFRMAT.BAS
< prev
next >
Wrap
BASIC Source File
|
1988-09-10
|
5KB
|
198 lines
'$INCLUDE:'QBTOOLS.INC'
'----------------------------------
'| NFRMAT - Formats numeric entry
'| SYNTAX:
'| CALL nfrmat(strng$,mode%,p%)
'| | | +- Position of "-" for mode 6
'| | +----- Mode or formatting level
'| +------------ String or variable to format.
'| If formatting is requested, the formatted
'| string is returned in this variable.
'|
'| mode 0 = Disallow "-" as an element (numbers ONLY)
'| 1 = Allow "-" as an element
'| 2 = Formatting to phone type (7 digit: xxx-xxxx)
'| 3 = Formatting to phone type (10 digit: xxx-xxx-xxxx)
'| 4 = Formatting to social security style (xxx-xx-xxxx)
'| 5 = Extract numbers from string sent, no exclusions
'| 6 = Extract numbers, place "-" in position p
'+-----------------------------------
'| Possible Returns:
'|
'| M=99;STRNG$="Numeric Entry Only!" -Input had non numeric characters
'| M=98;STRNG$="Too long-Looking for xx Digit [Phone/Social Security] Number!"
'| M=97;STRNG$="Too short-Looking for xx Digit [Phone/Social Security] Number!"
'| M=50;STRNG$="Programmer Error - Invalid mode specified." (you screwed up)
'| M=unchanged;STRNG$=numeric string formatted to specifications
'+----------------------------------
'| Copr. InfoSoft 1986, 1987, 1988
'| ALL RIGHTS RESERVED
'-----------------------------------
SUB numberformat(nst$, m%, p%) STATIC
DEFINT A-Z
STATIC c$, l, z, l1, x ' maybe narry$() and raw$() too
st$="": mst$="": l=0 : z=1
l1=LEN(nst$)
IF l1=0 AND m=6 THEN EXIT SUB ' get LEN of strng passed
REDIM raw$(l1)
FOR y=1 TO l1 'count numeric elements in st$
c$=MID$(nst$,y,1)
raw$(y)=c$ ' parse elements into array
IF ASC(c$) =>48 AND ASC(c$) <=57 THEN
l=l+1
END IF
NEXT y ' l is number of nums, raw$ is raw array
REDIM narry$(l) 'dim array to exact length
FOR x=1 TO l1 ' store just the nums in array
c$=raw$(x)
IF INSTR("0123456789",c$) THEN
narry$(z)=c$
z=z+1
END IF
NEXT x
'
SELECT CASE m
CASE 0 : GOTO num.only
CASE 1 : GOTO dash
CASE 2 : GOTO phone7
CASE 3 : GOTO phone10
CASE 4 : GOTO soc.sec
CASE 5 : GOTO extr.num
CASE 6 : GOTO acct.num
CASE ELSE
m=50
nst$="Invalid mode specified."
EXIT SUB
END SELECT
num.only:
nst$=""
FOR x=1 TO l1
c$=raw$(x)
IF ASC(c$) < 47 OR ASC(c$) >58 THEN ' check for num between 0-9
nst$="Numeric Entry Only"
m=99
EXIT SUB
ELSE
nst$=nst$+c$
END IF
NEXT x
EXIT SUB
dash:
nst$=""
FOR x=1 TO l1
c$=raw$(x)
IF INSTR("0123456789-",c$) THEN
nst$=nst$+c$
ELSE
nst$="Invalid Characters in Input"
m=99
EXIT SUB
END IF
NEXT X
EXIT SUB
phone7:
IF l>7 THEN
nst$="Too long - Looking for a 7 Digit Phone Number!"
m=98
EXIT SUB
ELSEIF l<7 THEN
nst$="Too short - Looking for a 7 Digit Phone Number!"
m=97
EXIT SUB
END IF
nst$=""
FOR x=(l-6) TO (l-4)
nst$=nst$+narry$(x)
NEXT x
nst$=nst$+"-"
'
FOR x=(l-3) TO l
nst$=nst$+narry$(x)
NEXT x
EXIT SUB
phone10:
IF l>10 THEN
nst$="Too long - Looking for a 10 Digit Phone Number!"
m=98
EXIT SUB
ELSEIF l<10 AND m=3 THEN
nst$="Too short - Looking for a 10 Digit Phone Number!"
m=97
EXIT SUB
END IF
nst$="("+narry$(1)+narry$(2)+narry$(3)+") "
FOR x=4 TO 6
nst$=nst$+narry$(x)
NEXT x
nst$=nst$+"-"
FOR x=7 TO 10
nst$=nst$+narry$(x)
NEXT x
EXIT SUB
soc.sec:
nst$=""
IF l>9 THEN
nst$="Too long - Social Security Numbers are only 9 Digits !"
m=98
EXIT SUB
ELSEIF l<9 THEN
nst$="Too short - Social Security Numbers are 9 Digits !"
m=97
EXIT SUB
END IF
FOR x=1 TO 3
nst$=nst$+narry$(x)
NEXT x
nst$=nst$+"-"
FOR x=4 TO 5
nst$=nst$+narry$(x)
NEXT x
nst$=nst$+"-"
FOR x=6 TO 9
nst$=nst$+narry$(x)
NEXT x
EXIT SUB
'
extr.num:
nst$=""
FOR x=1 TO l
nst$=nst$+narry$(x)
NEXT x
EXIT SUB
acct.num:
nst$=""
FOR x=1 TO (p-1)
nst$=nst$+narry$(x)
NEXT x
nst$=nst$+"-"
FOR x=p TO l
nst$=nst$+narry$(x)
NEXT x
END SUB